#include "UIControl.h"
#include "Scene.h"

using namespace GalliumEngine;


UIControl::UIControl(void)
{
}

UIControl::UIControl(std::string _id)
{
	this->id = _id;
	scale = Matrix3(false);
}


UIControl::~UIControl(void)
{

}

void UIControl::bind()
{
	glGenBuffers(1, &vertexbuffer);
	glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
	glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(Vector3), &vertices[0], GL_STATIC_DRAW);

	glGenBuffers(1, &uvbuffer);
	glBindBuffer(GL_ARRAY_BUFFER, uvbuffer);
	glBufferData(GL_ARRAY_BUFFER, uvs.size() * sizeof(Vector2), &uvs[0], GL_STATIC_DRAW);
}

void UIControl::initialize()
{
	this->rotationZ = Quaternion(1,0,0,0);
	this->depth = 0.0f;
}

void UIControl::deinitialize()
{
	vertices.clear();
	uvs.clear();
	params.clear();

	glDeleteBuffers(1, &vertexbuffer);
	glDeleteBuffers(1, &uvbuffer);
}

Quaternion UIControl::getRotationZ()
{
	return rotationZ;
}

std::vector<Vector3> UIControl::getVertices()
{
	return vertices;
}

std::vector<Vector2> UIControl::getUvs()
{
	return uvs;
}

void UIControl::setRotationZ(Quaternion _q)
{
	rotationZ = _q;
}

Scene* UIControl::getScene()
{
	return scene;
}

void UIControl::setScene(Scene* _scene)
{
	scene = _scene;
}

GLuint UIControl::getVertexbuffer()
{
	return vertexbuffer;
}

GLuint UIControl::getUvbuffer()
{
	return uvbuffer;
}

void UIControl::addVertex(Vector3 _vertex)
{
	this->vertices.push_back(_vertex);
}

void UIControl::addUv(Vector2 _uv)
{
	this->uvs.push_back(_uv);
}

void UIControl::setControlLocal(Matrix4 _local)
{
	controlLocal = _local;
}

void UIControl::setControlWorld(Matrix4 _world)
{
	controlWorld = _world;
}

Matrix4 UIControl::getControlLocal()
{
	return controlLocal;
}

Matrix4 UIControl::getControlWorld()
{
	return controlWorld;
}


void UIControl::setSize(Vector2 _size)
{
	this->size = _size;
}

Vector2 UIControl::getSize()
{
	return size;
}

void UIControl::setPosition(Vector2 _position)
{
	this->position = _position;
}

Vector2 UIControl::getPosition()
{
	return position;
}

void UIControl::setDepth(int _depth)
{
	this->depth = (float)MathUtils::clamp<float>(0.0f,(float)_depth,255.0f) / 255.0f;
}

float UIControl::getDepth()
{
	return depth;
}

void UIControl::setVisible(bool _visible)
{
	visible = _visible;
}

void UIControl::setShader(Shader* _shader)
{
	shader = _shader;
}

Shader* UIControl::getShader()
{
	return shader;
}

void UIControl::setColour(Colour _colour)
{
	colour = _colour;
}

Colour UIControl::getColour()
{
	return colour;
}

void UIControl::setVertexShader(std::string _vertexShader)
{
	vertexShader = _vertexShader;
}

void UIControl::setFragmentShader(std::string _fragmentShader)
{
	fragmentShader = _fragmentShader;
}

void UIControl::addShaderParam(BindParams param)
{
	params.push_back(param);
}

std::vector<BindParams> UIControl::getShaderParams()
{
	return params;
}

std::string UIControl::getId()
{
	return id;
}

void UIControl::setParent(UIControl *ui)
{
	this->parent = ui;
}

bool UIControl::getVisible()
{
	return visible;
}

Matrix3 UIControl::getScale()
{
	return scale;
}

void UIControl::setScale(Matrix3 _scale)
{
	scale = _scale;
}

void UIControl::update(float delta)
{

}

void UIControl::draw()
{

}
